home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 109_01.zip / PG.C < prev    next >
Text File  |  1993-06-26  |  3KB  |  87 lines

  1. /*
  2.     PAGE:   Currently setup for TRS-80 Model II operation.
  3.  
  4.     Paging routine - outputs 'pagelength' lines (of ASCII text)
  5.     to standard output then waits for KB input to continue with
  6.     the next page of 'pagelength' lines.
  7.     If the KB input is the F1 key the next ('pagelength' / 2) lines
  8.     (half page) will be output, any other key outputs a full page.
  9.     
  10.     Notes: The BREAK key will cause an orderly exit back to CP/M.
  11.            If 'pagelength' is not specified it defaults to 23 lines.
  12.  
  13.     Usage: pg [-pagelength] filename
  14.  
  15.     Bugs: None that I know of.
  16.  
  17.     Environment: CP/M 2.2 (P&T)
  18.           BDS C compiler Rev. 1.42
  19.  
  20.     Author: Jack S. Bakeman, Jr.
  21.             1222 Inverrary Ln.
  22.             Deerfield, IL 60015
  23.         (312) 459-0565
  24. */
  25.  
  26. #include "bdscio.h"
  27. #define BRK  0x03    /* BREAK key on the TRS-80 Model II      */
  28. #define F1   0x01    /* Function key F1 on the TRS-80 Model II */
  29.  
  30. main(argc, argv)
  31. char **argv;
  32. {
  33.     char ibuf[BUFSIZ], linbuf[MAXLINE];
  34.     char length[6];
  35.     int c,i;
  36.     int pglen;
  37.     
  38.     if (argc < 2)        /* User has given no arguments to process */
  39.         {
  40.         printf("Usage: pg [-pagelength] filename\n");
  41.         exit();
  42.         }
  43.     if (argc == 2)        /* User has not specified a pagelength */
  44.         {
  45.         pglen = 23;        /* Default pagelength */
  46.         if (fopen(argv[1], ibuf) == ERROR)
  47.             {
  48.             printf("Can't open %s\n", argv[1]);
  49.             exit();
  50.             }
  51.         }
  52.     if (argc >= 3)        /* Both arguments have been supplied */
  53.         {
  54.         if(*(argv[1]) == '-')    /* Check pagelength for possible typos */
  55.             {
  56.             strcpy(length,argv[1]);
  57.             for (i = 1; length[i] != NULL; i++)
  58.                 if (isalpha(length[i]))
  59.                     length[i] = NULL;
  60.             pglen = ((i = abs(atoi(length))) > 0) ? i : 23;    /* NEVER = 0 */
  61.             if (fopen(argv[2], ibuf) == ERROR)
  62.                 {
  63.                 printf("Can't open %s\n", argv[2]);
  64.                 exit();
  65.                 }
  66.             }
  67.         else        /* Garbage 1st. argument */
  68.             {
  69.             printf("Unknown flag\n");
  70.             exit();
  71.             }
  72.         }
  73.     while (1)        /* Work gets done here, above is just a parser */
  74.         {
  75.         for (i = 0; i < ((c == F1) ? pglen/2 : pglen); i++)
  76.             {
  77.             if (fgets(linbuf, ibuf) != 0)
  78.                  printf("%s", linbuf);
  79.             else        /* EOF or CNTL Z reached */
  80.                  exit();
  81.             }
  82.     if ((c = bios(3)) == BRK) /* Raw character input, no console echo */
  83.         break;
  84.         }
  85.     fclose(ibuf);
  86. }
  87.